$(function(){
    axios.defaults.baseURL ='http://www.liulongbin.top:3007'
    let form = layui.form
    form.verify({
        nickname:[
            /^[\S]{1,10}$/,
            '昵称的长度为1-10个字符'
        ]
    })
    let layer = layui.layer
    initUserInfo()
    function initUserInfo(){
        axios({
            method:'get',
            url:'/my/userinfo',
        headers: {Authorization:localStorage.getItem('token')},

        }).then(res=>{
            if(res.data.status !== 0){
                return layer.msg(res.data.message)
            }
            form.val('formUserInfo',res.data.data)
        })
    }
    // 重置
    $('#btnReset').on('click',function(e){
        e.preventDefault()
        initUserInfo()
    })
    // 提交
    $('form').on('submit',function(e){
        e.preventDefault()
        axios({
            method:'post',
            url:'/my/userinfo',
            data:$(this).serialize(),
        }).then(({data:res})=>{
            // console.log(res);
            if(res.status !=0){
                return layer.msg(res.message)
            }
            layer.msg('恭喜你，修改成功')
            window.parent.getUserInfo()
            // console.log(window.parent.getUserInfo());
        })
    })
})